<?php
include_once('common/header.php');
if($AppUI->id <=0) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 		= $objRequest->getParams();
$intAction		= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$intDetail		= isset($arrParams['de']) ? $arrParams['de'] : 0;
$arrReportId	= isset($arrParams['preportid']) ? $arrParams['preportid'] : null;
$intError		= 0;
$intMessage		= 0;
if($intAction > 0 && $arrReportId) {
	switch($intAction) {
		case 1:
		case 3:
		case 5:
			if(isset($_SESSION['report']) && (($_SESSION['report']&1<<5)>0)) {				
				$objReport 	= new Report();
				if($intAction == 1) $intStatus = 1;
				elseif($intAction == 3) $intStatus = 2;
				elseif($intAction == 5) $intStatus = 3;	
				if($intDetail == 0) {
					foreach($arrReportId as $value) {
						$intUserId	= $objRequest->getParam('puserid' . $value, 0);					
						$objReport->updateStatus($AppUI->id, $value, $intStatus, 32, $intUserId);
					}	
				} else {
					$intUserId		= $objRequest->getParam('uid', 0);
					$intReportId	= (int)$arrReportId;
					$intError 		= $objReport->updateStatus($AppUI->id, $intReportId, $intStatus, 32, $intUserId);
				}
				if($intError == 0) {
					$intMessage	= 7;
				}
			} else {
				$intError = 18;
			}
			break;
		case 2:
			if(isset($_SESSION['report']) && (($_SESSION['report']&1<<3)>0)) {
				$objReport 	= new Report();
				if($intDetail == 0) {
					foreach($arrReportId as $value) {
						$objReport->updateStatus($AppUI->id, $value, 4, 8);
					}
				} else {
					$intReportId	= (int)$arrReportId;
					$intError 		= $objReport->updateStatus($AppUI->id, $intReportId, 4, 8);
				}
				if($intError == 0) {
					$intMessage	= 8;
				}
			} else {
				$intError = 18;
			}
			break;
		case 4:
			if(isset($_SESSION['report']) && (($_SESSION['report']&1<<3)>0) && $AppUI->type > 1) {
				$objReport = new Report();
				if($intDetail == 0) {
					foreach($arrReportId as $value) {
						$objReport->delete($AppUI->id, $value);
					}
				} else {
					$intReportId	= (int)$arrReportId;
					$intError 		= $objReport->delete($AppUI->id, $intReportId);
				}
				if($intError == 0) {
					$intMessage	= 9;
				}
			} else {
				$intError = 18;
			}
			break;		
	}
} else {
	$intError = 18;
}
if($intError > 0) {
	if($intDetail) {
		if($intError == 1) $intError = 18;
		elseif($intError == 2) $intError = 20;
	}
	Vfriend_Function::setError($arrError[$intError]);
} else {
	Vfriend_Function::setMsg($arrMessage[$intMessage]);
}
if($intDetail == 0) {
	$strRefer	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
	Vfriend_Function::redirect($strRefer);
} else {
	$intReportId	= (int)$arrReportId;
	$strRefer		= $objRequest->getParam('refer','');	
	Vfriend_Function::redirect(HOST_BACKEND . 'index/detail?reportid=' . $intReportId . '&refer=' . $strRefer);
}

?>